Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/app/estimation/[id]/page.tsx9 * Module : app10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-08-0912 * Last Modified : 2026-08-1313 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import type { Metadata } from "next";43import { cache } from "react";44import { notFound } from "next/navigation";45import { estimateByUnitId } from "@/lib/estimator";46import ResultView from "@/components/ResultView";47import {48 EST_YEAR,49 SITE_URL,50 TYPE_LABELS,51 moneyFr,52 slugify,53} from "@/lib/seo";5455export const dynamic = "force-dynamic";5657// Une seule estimation par requête, partagée entre generateMetadata et la page.58const getEstimate = cache((id: string) => estimateByUnitId(id));5960function displayAddress(unit: {61 adresse: string | null;62 specs: { apt: string | null };63 municipalite: string | null;64}): string {65 const apt = unit.specs.apt ? `, app. ${unit.specs.apt}` : "";66 const addr = unit.adresse ?? "Propriété";67 return unit.municipalite ? `${addr}${apt}, ${unit.municipalite}` : `${addr}${apt}`;68}6970export async function generateMetadata({71 params,72}: {73 params: Promise<{ id: string }>;74}): Promise<Metadata> {75 const { id } = await params;76 const decoded = decodeURIComponent(id);77 const data = getEstimate(decoded);78 if (!data?.unit) return { title: "Propriété introuvable" };79 const u = data.unit;80 const r = data.result;81 const typeLabel = TYPE_LABELS[u.typeProp]?.singulier ?? "propriété";82 const annee = u.anneeConstruction ? `, construite en ${u.anneeConstruction}` : "";83 const title = `${displayAddress(u)} — estimation ${EST_YEAR} : ${moneyFr(r.estimate)}`;84 const description = `Valeur estimée de cette ${typeLabel}${annee} : ${moneyFr(85 r.estimate86 )} (fourchette ${moneyFr(r.low)} – ${moneyFr(r.high)}, confiance ${87 r.confidenceLevel88 }). Valeur au rôle, historique 2021-${EST_YEAR} et comparables réels — calcul montré en entier.`;89 return {90 title,91 description,92 alternates: { canonical: `/estimation/${encodeURIComponent(decoded)}` },93 openGraph: { title, description, type: "website" },94 };95}9697/** JSON-LD schema.org : la propriété comme lieu résidentiel + fil d'Ariane. */98function unitJsonLd(data: NonNullable<ReturnType<typeof estimateByUnitId>>) {99 const u = data.unit!;100 const r = data.result;101 const schemaType =102 u.typeProp === "unifamilial" || u.typeProp === "chalet" || u.typeProp === "maison_mobile"103 ? "SingleFamilyResidence"104 : u.typeProp === "plex" || u.typeProp === "condo_ou_multi"105 ? "Residence"106 : "Place";107 const url = `${SITE_URL}/estimation/${encodeURIComponent(u.id)}`;108 const place: Record<string, unknown> = {109 "@type": schemaType,110 "@id": `${url}#place`,111 name: displayAddress(u),112 url,113 address: {114 "@type": "PostalAddress",115 streetAddress: u.adresse ?? undefined,116 addressLocality: u.municipalite ?? undefined,117 addressRegion: "QC",118 addressCountry: "CA",119 },120 geo: { "@type": "GeoCoordinates", latitude: u.lat, longitude: u.lng },121 additionalProperty: [122 {123 "@type": "PropertyValue",124 name: `Estimation Vrai-Prix ${EST_YEAR}`,125 value: r.estimate,126 unitText: "CAD",127 },128 {129 "@type": "PropertyValue",130 name: "Valeur au rôle d'évaluation",131 value: u.valeurRole ?? undefined,132 unitText: "CAD",133 },134 ],135 };136 if (u.aireEtagesM2) {137 place.floorSize = {138 "@type": "QuantitativeValue",139 value: u.aireEtagesM2,140 unitCode: "MTK",141 };142 }143 if (u.anneeConstruction) place.yearBuilt = u.anneeConstruction;144 const breadcrumb = {145 "@type": "BreadcrumbList",146 itemListElement: [147 { "@type": "ListItem", position: 1, name: "Accueil", item: SITE_URL },148 u.municipalite149 ? {150 "@type": "ListItem",151 position: 2,152 name: u.municipalite,153 item: `${SITE_URL}/municipalite/${slugify(u.municipalite)}`,154 }155 : null,156 {157 "@type": "ListItem",158 position: u.municipalite ? 3 : 2,159 name: u.adresse ?? u.id,160 item: url,161 },162 ].filter(Boolean),163 };164 return { "@context": "https://schema.org", "@graph": [place, breadcrumb] };165}166167export default async function EstimationPage({168 params,169}: {170 params: Promise<{ id: string }>;171}) {172 const { id } = await params;173 const data = getEstimate(decodeURIComponent(id));174 if (!data) notFound();175 return (176 <>177 {data.unit && (178 <script179 type="application/ld+json"180 dangerouslySetInnerHTML={{ __html: JSON.stringify(unitJsonLd(data)) }}181 />182 )}183 <ResultView data={data} />184 </>185 );186}187